<template>
  <div class="combination-add-chunk2">
    <div class="head">
      <el-form ref="dataForm" :inline="true" label-width="80px" :model="dataForm" class="demo-form-inline">
        <el-form-item label="选择模型" prop="model">
          <el-select v-model="dataForm.model" placeholder="请选择" style="width: 140px;" size="mini" @change="modelChangeHandle">
            <el-option :label="item.name" :value="item.id" v-for="item in modelList" :key="item.id" :disabled="item.id==1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="基准" prop="base" label-width="52px">
          <el-select v-model="dataForm.base" placeholder="请选择" style="width: 140px;" size="mini" @change="baseChangeHandle">
            <el-option :label="item.name" :value="item.id" v-for="item in baseList" :key="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="初始资金" prop="startMoney">
          <el-input-number v-model="dataForm.portfolioInitMoney" clearable placeholder="请输入" style="width: 160px;" size="mini" @change="startMoneyChangeHandle" :controls="false"></el-input-number>  万元
        </el-form-item>
        <el-form-item v-if="dataForm.model" label-width="135px" label="配置模型计算频率" prop="frequency">
          <el-select v-model="dataForm.frequency" placeholder="请选择" style="width: 140px;" size="mini" @change="frequencyChangeHandle">
            <el-option :label="item.name" :value="item.id" v-for="item in frequencyList" :key="item.id"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <div class="body">
      <el-table
        v-if="list.length&&dataForm.model"
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        stripe fit
        size="mini"
        max-height="465"
        :header-cell-style="{background:'#dcedff',color:'#32639d'}"
        style="width: 100%;"
      >
        <el-table-column label="操作" width="50" fixed align="center">
          <template slot-scope="{$index}">
            <i class="el-icon-delete" style="cursor: pointer;" @click="deleteHandle($index)"></i>
          </template>
        </el-table-column>
        <el-table-column type="index" label="序号" align="center" fixed width="60"></el-table-column>
        <el-table-column prop="strategyInfoVo.strategyName" label="策略名称" fixed min-width="220" show-overflow-tooltip> 
          <template slot-scope="{row}">
            <span v-strategy="{id:row.strategyInfoVo.strategyId, userId}">{{row.strategyInfoVo.strategyName}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="weight" label="预期年化收益率(%)" align="center" width="190">
          <template slot="header" slot-scope="">
            <div style="flex">
              <el-select class="tableHead-select" v-model="tableSelect1" size="mini" placeholder="请选择" @change="incomSegmentTableHeadChangeHandle" style="width: 54px;">
                <el-option
                  v-for="item in options1"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>  
              <span>预期年化收益率(%)</span>
            </div>
          </template>
          <template slot-scope="{$index}">
            <el-select class="tableCell-select" v-model="tableRiskData[$index].incomSegment" size="mini" placeholder="请选择" @change="incomSegmentChangeHandle($index)" style="width: 58px;">
              <el-option
                v-for="item in options2"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-input-number v-model="tableRiskData[$index].annualizedIncome" :disabled="tableRiskData[$index].incomSegment!=999" style="width: 70px" size="mini" :controls="false"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column prop="weight" label="预期年化波动率(%)" align="center" width="190">
          <template slot="header" slot-scope="">
          <div style="flex">
            <el-select class="tableHead-select" v-model="tableSelect2" size="mini" placeholder="请选择" @change="fluctuationsSegmentTableHeadChangeHandle" style="width: 54px;">
              <el-option
                v-for="item in options1"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>  
            <span>预期年化波动率(%)</span>
          </div>
          </template>
          <template slot-scope="{$index}">
            <el-select class="tableCell-select" v-model="tableRiskData[$index].fluctuationsSegment" size="mini" placeholder="请选择" @change="fluctuationsSegmentChangeHandle($index)" style="width: 58px;">
              <el-option
                v-for="item in options2"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>  
            <el-input-number v-model="tableRiskData[$index].annualFluctuations" :disabled="tableRiskData[$index].fluctuationsSegment!=999" style="width: 70px" size="mini" :controls="false"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column prop="percentageDown" label="占比下限(%)" align="center" width="120">
          <template slot-scope="{$index}">
            <el-input-number v-model="tableRiskData[$index].percentageDown" style="width: 70px" @change="percentageDownHandleChange($index)" :min="0" :max="100" size="mini" :controls="false"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column prop="percentageUp" label="占比上限(%)" align="center" width="120">
          <template slot-scope="{$index}">
            <el-input-number v-model="tableRiskData[$index].percentageUp" style="width: 70px" @change="percentageUpHandleChange($index)" :min="0" :max="100" size="mini" :controls="false"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column prop="" label="今年以来收益率" align="center" width="150">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['0']&&netWorthExtendBeanList[$index]['0'].incomeRate" :class="netWorthExtendBeanList[$index]['0'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['0'].incomeRate }}%  
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="今年以来波动率" align="center" width="150">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['0']&&netWorthExtendBeanList[$index]['0'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['0'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近1月收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['1']&&netWorthExtendBeanList[$index]['1'].incomeRate" :class="netWorthExtendBeanList[$index]['1'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['1'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近1月波动率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['1']&&netWorthExtendBeanList[$index]['1'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['1'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近3月收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['3']&&netWorthExtendBeanList[$index]['3'].incomeRate" :class="netWorthExtendBeanList[$index]['3'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['3'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近3月波动率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['3']&&netWorthExtendBeanList[$index]['3'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['3'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近6月收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['6']&&netWorthExtendBeanList[$index]['6'].incomeRate" :class="netWorthExtendBeanList[$index]['6'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['6'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近6月波动率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['6']&&netWorthExtendBeanList[$index]['6'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['6'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近1年收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['12']&&netWorthExtendBeanList[$index]['12'].incomeRate" :class="netWorthExtendBeanList[$index]['12'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['12'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近1年波动率" align="center" width="130">
           <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['12']&&netWorthExtendBeanList[$index]['12'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['12'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近2年收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['24']&&netWorthExtendBeanList[$index]['24'].incomeRate" :class="netWorthExtendBeanList[$index]['24'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['24'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近2年波动率" align="center" width="130">
           <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['24']&&netWorthExtendBeanList[$index]['24'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['24'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近3年收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['36']&&netWorthExtendBeanList[$index]['36'].incomeRate" :class="netWorthExtendBeanList[$index]['36'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['36'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近3年波动率" align="center" width="130">
           <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['36']&&netWorthExtendBeanList[$index]['36'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['36'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="收益率" align="center" width="150">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['99']&&netWorthExtendBeanList[$index]['99']&&netWorthExtendBeanList[$index]['99'].incomeRate" :class="netWorthExtendBeanList[$index]['99'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['99'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="波动率" align="center" width="150">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['99']&&netWorthExtendBeanList[$index]['99']&&netWorthExtendBeanList[$index]['99'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['99'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
      </el-table>
      <el-table
        v-if="list.length&&(!dataForm.model)"
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        stripe fit
        size="mini"
        max-height="465"
        :header-cell-style="{background:'#dcedff',color:'#32639d'}"
        style="width: 100%;"
      >
        <el-table-column label="操作" width="50" fixed align="center">
          <template slot-scope="{$index}">
            <i class="el-icon-delete" style="cursor: pointer;" @click="deleteHandle($index)"></i>
          </template>
        </el-table-column>
        <el-table-column type="index" label="序号" align="center" fixed width="60"></el-table-column>
        <el-table-column prop="strategyInfoVo.strategyName" label="策略名称" fixed min-width="220" show-overflow-tooltip> 
          <template slot-scope="{row}">
            <span v-strategy="{id:row.strategyInfoVo.strategyId, userId}">{{row.strategyInfoVo.strategyName}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="weight" label="配置权重(%)" align="center" width="120">
          <template slot-scope="{$index}">
            <el-input-number v-model="list[$index].weight" style="width: 70px" label="haha" @change="weightHandleChange($index)" :min="0" :max="100" :precision="2" size="mini" :controls="false"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column prop="" label="今年以来收益率" align="center" width="150">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['0']&&netWorthExtendBeanList[$index]['0'].incomeRate" :class="netWorthExtendBeanList[$index]['0'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['0'].incomeRate }}%  
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="今年以来波动率" align="center" width="150">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['0']&&netWorthExtendBeanList[$index]['0'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['0'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近1月收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['1']&&netWorthExtendBeanList[$index]['1'].incomeRate" :class="netWorthExtendBeanList[$index]['1'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['1'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近1月波动率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['1']&&netWorthExtendBeanList[$index]['1'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['1'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近3月收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['3']&&netWorthExtendBeanList[$index]['3'].incomeRate" :class="netWorthExtendBeanList[$index]['3'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['3'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近3月波动率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['3']&&netWorthExtendBeanList[$index]['3'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['3'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近6月收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['6']&&netWorthExtendBeanList[$index]['6'].incomeRate" :class="netWorthExtendBeanList[$index]['6'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['6'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近6月波动率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['6']&&netWorthExtendBeanList[$index]['6'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['6'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近1年收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['12']&&netWorthExtendBeanList[$index]['12'].incomeRate" :class="netWorthExtendBeanList[$index]['12'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['12'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近1年波动率" align="center" width="130">
           <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['12']&&netWorthExtendBeanList[$index]['12'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['12'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近2年收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['24']&&netWorthExtendBeanList[$index]['24'].incomeRate" :class="netWorthExtendBeanList[$index]['24'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['24'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近2年波动率" align="center" width="130">
           <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['24']&&netWorthExtendBeanList[$index]['24'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['24'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近3年收益率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['36']&&netWorthExtendBeanList[$index]['36'].incomeRate" :class="netWorthExtendBeanList[$index]['36'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['36'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="近3年波动率" align="center" width="130">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['36']&&netWorthExtendBeanList[$index]['36'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['36'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="收益率" align="center" width="150">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['99']&&netWorthExtendBeanList[$index]['99']&&netWorthExtendBeanList[$index]['99'].incomeRate" :class="netWorthExtendBeanList[$index]['99'].incomeRate>=0?'positiveFc':'negativeFc'">
              {{ netWorthExtendBeanList[$index]['99'].incomeRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="波动率" align="center" width="150">
          <template slot-scope="{$index}">
            <span v-if="netWorthExtendBeanList[$index]['99']&&netWorthExtendBeanList[$index]['99']&&netWorthExtendBeanList[$index]['99'].volatilityRate">
              {{ netWorthExtendBeanList[$index]['99'].volatilityRate }}%
            </span>
            <span v-else>--</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { findPortfolioStrategy } from '@/api/combination'
import { mapGetters } from 'vuex'

export default {
  props: {
    chunk1_res: {
      type: Array,
      default: () => {
        return []
      }
    },
    deleteIndex: {
      type: Number
    }
  },
  data() {
    return {
      listLoading: false,
      list: [],
      netWorthExtendBeanList: [],
      weight_list: [],
      have_weight: 0,
      dataForm: {
        model: 0,
        base: 9,
        frequency: 1,
        portfolioInitMoney: undefined
      },
      tableRiskData: [],
      modelList: [
        { id: 0, name: '等权重' },
        { id: 1, name: '均值方差' }, 
        { id: 2, name: '风险平价' }
      ],
      baseList: [
        { id: 9, name: '沪深300' },
        { id: 11, name: '中证500' },
        { id: 7, name: '上证50' }
      ],
      frequencyList: [
        { id: 1, name: '周频' },
        { id: 2, name: '月频' }
      ],

      options1: [
        { value: 1, label: '近1月' },
        { value: 3, label: '近3月' },
        { value: 6, label: '近6月' },
        { value: 12, label: '近1年' },
        { value: 24, label: '近2年' },
        { value: 36, label: '近3年' }
      ],
      options2: [
        { value: 1, label: '近1月' },
        { value: 3, label: '近3月' },
        { value: 6, label: '近6月' },
        { value: 12, label: '近1年' },
        { value: 24, label: '近2年' },
        { value: 36, label: '近3年' }, 
        { value: 999, label: '自定义' }
      ],
      tableSelect1: 12,
      tableSelect2: 12,
    }
  },
  computed: {
    ...mapGetters([
      'userId'
    ])
  },
  created() {
    if(this.chunk1_res.length>1) {
      this.getList(this.chunk1_res)
    }
  },
  methods: {
    incomSegmentTableHeadChangeHandle(val) {
      this.tableRiskData.forEach((item, i) => {
        item.incomSegment = val
        if(val<12) {
          item.annualizedIncome = ((((1 + (this.list[i].netWorthExtendBean[val].incomeRate)/100) ** (12/val)) - 1) * 100).toFixed(2)
        }else {
          item.annualizedIncome = this.list[i].netWorthExtendBean[val].incomeRate
        }
      })
    },
    incomSegmentChangeHandle(i) {
      const key = this.tableRiskData[i].incomSegment
      if(key==999) {
        this.tableRiskData[i].annualizedIncome = null
      }else {
        if(key<12) {
          this.tableRiskData[i].annualizedIncome = ((((1 + (this.list[i].netWorthExtendBean[key].incomeRate)/100) ** (12/key)) - 1) * 100).toFixed(2)
        }else {
          this.tableRiskData[i].annualizedIncome = this.list[i].netWorthExtendBean[key].incomeRate
        }
      }
      if(this.tableRiskData[i].annualFluctuations == null) {
        this.tableRiskData[i].incomSegment = 999
      }
    },
    fluctuationsSegmentTableHeadChangeHandle(val) {
      this.tableRiskData.forEach((item, i) => {
        item.fluctuationsSegment = val
        if(val<12) {
          item.annualFluctuations = ((((1 + (this.list[i].netWorthExtendBean[val].volatilityRate)/100) ** (12/val)) - 1) * 100).toFixed(2)
        }else {
          item.annualFluctuations = this.list[i].netWorthExtendBean[val].volatilityRate
        }
      })
    },
    fluctuationsSegmentChangeHandle(i) {
      const key = this.tableRiskData[i].fluctuationsSegment
      if(key==999) {
        this.tableRiskData[i].annualFluctuations = null
      }else {
        if(key<12) {
          this.tableRiskData[i].annualFluctuations = ((((1 + (this.list[i].netWorthExtendBean[key].volatilityRate)/100) ** (12/key)) - 1) * 100).toFixed(2)
        }else {
          this.tableRiskData[i].annualFluctuations = this.list[i].netWorthExtendBean[key].volatilityRate
        }
      }
      if(this.tableRiskData[i].annualFluctuations == null) {
        this.tableRiskData[i].fluctuationsSegment = 999
      }
    },
    percentageDownHandleChange(i) {
      if(this.tableRiskData[i].percentageDown>this.tableRiskData[i].percentageUp) {
        this.$message({
          message: '占比下限必须小于占比上限',
          type: 'warning'
        })
        this.$nextTick(() => {
          this.tableRiskData[i].percentageDown = this.tableRiskData[i].percentageUp
        })
      }
    },
    percentageUpHandleChange(i) {
    },
    deleteHandle(i) {
      const id = this.list[i].strategyInfoVo.strategyId
      if(this.list.length<=2) {
        this.$message({
          message: '至少添加两个以上产品！',
          type: 'warning'
        })
        return
      }
      this.list.splice(i,1)
      this.weight_list.splice(i,1)
      const _chunk1_res = JSON.parse(JSON.stringify(this.chunk1_res))
      _chunk1_res.splice(i,1)
      this.$emit('update:chunk1_res', _chunk1_res)
      this.$emit('update:deleteIndex', id)
    },
    frequencyChangeHandle(val) {
      this.tableRiskData.forEach(item => {
        item.frequency = val
      })
    },
    startMoneyChangeHandle(val) {
      this.$emit('startMoneyChange', val)
    },
    baseChangeHandle(id) {
      const res = this.baseList.find(item => item.id == id)
      this.$emit('baseChange', res)
    },
    modelChangeHandle(id) {
      this.$emit('modelChange', this.modelList[id])
    },
    weightHandleChange(i) {
      let total = 0
      this.list.forEach(item => {
        total += item.weight
      })
      if(total > 100) {
        this.$message({
          message: '超出最大权重',
          type: 'warning',
          duration: 2 * 1000
        })
        this.$nextTick(() => {
          this.have_weight = 0
          this.list[i].weight = this.list[i].weight - (total-100)
          this.weight_list = this.list.map(item => item.weight)
          this.$emit('weightChange', this.weight_list)
          this.$emit('haveWeightChange', this.have_weight)
        })
      }else {
        this.have_weight = 100 - total
        this.weight_list = this.list.map(item => item.weight)
        this.$emit('weightChange', this.weight_list)
        this.$emit('haveWeightChange', this.have_weight)
      }
    },
    addHandle() {},
    resetForm() {},
    getList(chunk1_res) {
      this.listLoading = true
      findPortfolioStrategy(chunk1_res).then(res => {
        this.listLoading = false
        this.netWorthExtendBeanList = res.body.map(item => item.netWorthExtendBean)
        let total_weight = 0
        this.weight_list = res.body.map((item, i) => {
          this.tableRiskData.push({
            strategyId: item.strategyInfoVo.strategyId,
            incomSegment: item.netWorthExtendBean[12]&&item.netWorthExtendBean[12].incomeRate ? 12 : 999,
            fluctuationsSegment: item.netWorthExtendBean[12]&&item.netWorthExtendBean[12].volatilityRate ? 12 : 999,
            annualizedIncome: item.netWorthExtendBean[12]&&item.netWorthExtendBean[12].incomeRate || null,
            annualFluctuations: item.netWorthExtendBean[12]&&item.netWorthExtendBean[12].volatilityRate || null,
            frequency: this.dataForm.frequency,
            percentageDown: 0,
            percentageUp: 100
          })
          item.percentageDown = 0
          item.percentageUp = 100
          total_weight += item.weight
          return item.weight
        })
        console.log(this.tableRiskData)
        this.have_weight = 100 - total_weight
        this.$emit('weightChange', this.weight_list)
        this.$emit('haveWeightChange', this.have_weight)
        this.list = res.body
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.combination-add-chunk2 {
  .head {
    padding: 15px;
    border: 1px solid #e1e0e0;
    background: rgba(225, 224, 224, 0.2);
    ::v-deep .el-form {
      .el-form-item {
        margin-bottom: 0;
      }
    }
  }
  .body {
    max-height: 495px;
    padding: 10px;
    margin-top: 15px;
    border: 1px solid #e1e0e0;
  }
}
</style>

